home *** CD-ROM | disk | FTP | other *** search
- Path: dtek.chalmers.se!d1mag
- From: d1mag@dtek.chalmers.se (Christian Magnusson)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: My code crashes my computer
- Date: 18 Mar 1996 00:00:17 GMT
- Organization: Chalmers University of Technology
- Message-ID: <4ii92h$ktm@nyheter.chalmers.se>
- References: <4igm25$poj@goofy.BrandonU.CA>
- NNTP-Posting-Host: gleen.dtek.chalmers.se
-
- In article <4igm25$poj@goofy.BrandonU.CA>, <menon@beijing.brandonu.ca> wrote:
- >This is an except from my program which shows where it crashes
- >
-
-
- >/***** READ_FILE *****/
- >void read_file(char *infile, char *infile2){
- > int i=0, x, y, garb;
- > FILE *fp;
- > char *s="File Error"; <-- char s[80] = "File Error";
- > char *comment="", buf; <-- char comment[80];
- <-- char buf[80];
- >
- > fp = fopen(infile, "r");
- > if (fp==NULL){
- > printf("FAILED!\n");
- > perror(s);
- > exit(1);
- > }
- > fgets(type,3,fp);
- > fscanf(fp,"%s",comment);
- > if (comment[0]=='#'){
- > do{
- > fscanf(fp, "%s",comment);
- > sprintf(buf,"%d",atoi(comment)); <---Crashes Here
- > }
- > while (strcmp(comment,buf));
-
-
- Hey... Try to learn how to use the char pointers! You are lucky that you
- could compile it at all.
-
- buf was assigned as a single character, not char buffer! sprintf must be
- used with a char pointer as it's first argument.
-
- comment was only defined as a char pointer. You didn't allocate any
- memory for that string!
-
- >
- >If anyone can help me, I would greatly appreciate it.
- >
-
- I hope that helped you a bit.
-
- /Mag
-
-
-
-
-
-
-
-
-
-
-
-
-
- --
- | Christian 'Mag' Magnusson Computer Science and Engineering
- | Email: d1mag@dtek.chalmers.se Chalmers University of Technology
- | GSM: +46 (0)705 380580 WWW: http://www.dtek.chalmers.se/~d1mag
- | http://www.dtek.chalmers.se/~d1mag/GPL.html (Gothenburg Pinball League)
-